
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})

INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/Half)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/Iex)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/Imath)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/IlmThread)

# ZLib
INCLUDE(FindZLIB)
IF(ZLIB_FOUND)
	MESSAGE(STATUS "Looking for zlib - found")
ELSE(ZLIB_FOUND)
	MESSAGE(STATUS "Looking for zlib - not found")
ENDIF(ZLIB_FOUND)

# Threading support
# Looks for pthreads and POSIX semaphores when not using win32 threads
# to generate IlmBaseConfig.h
INCLUDE(FindThreads)
IF(NOT CMAKE_USE_WIN32_THREADS_INIT AND CMAKE_USE_PTHREADS_INIT)
	SET(HAVE_PTHREAD 1)
	CHECK_INCLUDE_FILES("semaphore.h" HAVE_SEMAPHORE_H)
	IF(HAVE_SEMAPHORE_H)
		SET(REQUIRED_LIBRARIES_OLD ${CMAKE_REQUIRED_LIBRARIES})
		SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
		INCLUDE(CheckFunctionExists)
		CHECK_FUNCTION_EXISTS(sem_init HAVE_POSIX_SEMAPHORES)
		SET(CMAKE_THREAD_LIBS_INIT ${REQUIRED_LIBRARIES_OLD})
	ENDIF(HAVE_SEMAPHORE_H)
ENDIF(NOT CMAKE_USE_WIN32_THREADS_INIT AND CMAKE_USE_PTHREADS_INIT)

# Platform definitions for OpenEXRConfig.h
IF(CMAKE_SYSTEM_NAME STREQUAL "Linux")
	SET(HAVE_LINUX_PROCFS 1)
	# The original OpenEXR configure script sets this to 1 only in Linux
	SET(HAVE_LARGE_STACK 1)
ENDIF(CMAKE_SYSTEM_NAME STREQUAL "Linux")
IF(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
	SET(HAVE_DARWIN 1)
ENDIF(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
INCLUDE(CheckCXXSourceCompiles)
CHECK_CXX_SOURCE_COMPILES("#include <iomanip>\n#include <iostream>\nint main() { std::cout << std::right; return 0; }" HAVE_COMPLETE_IOMANIP)

# Create config files.
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/IlmBaseConfig.in.h ${CMAKE_CURRENT_BINARY_DIR}/IlmBaseConfig.h)
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/OpenEXRConfig.in.h ${CMAKE_CURRENT_BINARY_DIR}/OpenEXRConfig.h)

INSTALL(FILES 
	${CMAKE_CURRENT_BINARY_DIR}/IlmBaseConfig.h
	DESTINATION include/OpenEXR)

SUBDIRS(Half)
SUBDIRS(Iex)
SUBDIRS(Imath)
SUBDIRS(IlmThread)

IF(ZLIB_FOUND)
	SUBDIRS(IlmImf)
ENDIF(ZLIB_FOUND)

#ADD_SUBDIRECTORY(Half)
#ADD_SUBDIRECTORY(Iex)
#ADD_SUBDIRECTORY(Imath)
#ADD_SUBDIRECTORY(IlmThread)
#ADD_SUBDIRECTORY(IlmImf)

